package cn.tedu.hospitalqd.controller;

import cn.tedu.hospitalqd.pojo.dto.DoctorAddNewDTO;
import cn.tedu.hospitalqd.pojo.dto.DoctorUpdateDTO;
import cn.tedu.hospitalqd.pojo.vo.DoctorListItemVO;
import cn.tedu.hospitalqd.pojo.vo.DoctorStandardVO;
import cn.tedu.hospitalqd.service.DoctorService;
import cn.tedu.hospitalqd.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/doctors")
@Api(tags = "01.医生管理模块")
@Validated
public class DoctorController {
    @Autowired
    private DoctorService doctorService;
   @PostMapping("/add-new")
    @ApiOperation("添加医生")
    @ApiOperationSupport(order = 100)
   public JsonResult addNew(@Valid DoctorAddNewDTO addNewDTO){
        doctorService.addNew(addNewDTO);
        return JsonResult.ok();
   }
   @PostMapping("/{id:[0-9]+}/delete")
   @ApiOperation("根据ID删除医生")
   @ApiOperationSupport(order = 200)
   @ApiImplicitParams(value = {@ApiImplicitParam(name = "id",required = true,dataType = "long")})
   public JsonResult delete(@Range(min = 1,message = "删除医生失败，医生号无效！")
                            @PathVariable Long id){
       doctorService.delete(id);
       return JsonResult.ok();
   }

   @PostMapping("/{id:[0-9]+}/update")
   @ApiOperation("修改医生详情")
   @ApiOperationSupport(order = 300)
   @ApiImplicitParam(name = "id",value = "医生ID",required = true,dataType = "long")
   public JsonResult updateInfoById(@Range(min = 1,message = "修改医生失败，医生号无效！")
                                    @PathVariable Long id, @Valid DoctorUpdateDTO dto){
       log.debug("开始处理【修改医生详情】的请求，参数：{}", dto);
       doctorService.updateInfoById(id,dto);
       return JsonResult.ok();
   }




   @GetMapping("/{id:[0-9]+}")
   @ApiOperation("根据ID查询医生详情")
   @ApiOperationSupport(order = 410)
   @ApiImplicitParam(name = "id",value = "医生ID",required = true,dataType = "long")
   public JsonResult getStandardById(@Range(min = 1,message = "获取医生详情失败，ID值无效！")
                                     @PathVariable Long id){
      log.debug("开始处理【根据ID查询相册详情】的请求，参数：{}", id);
       DoctorStandardVO doctorStandardVO=doctorService.getStandardById(id);
       return JsonResult.ok(doctorStandardVO);
   }

   @GetMapping("")
   @ApiOperation("查询医生列表")
   @ApiOperationSupport(order = 420)
   public JsonResult list(){
       log.debug("开始处理【查询医生列表】的业务，无参数");
       List<DoctorListItemVO> list=doctorService.list();
       return JsonResult.ok(list);
   }


}
